<?php
/**
 ***** 扶摇而上、抱守本真 ******
 * @author Dana
 * @Date 2021/6/10
 */

class guest_book{
    public $comments;
    public $last_visitor;

    public function __construct($user)
    {
        $dbh = mysqli_connect('localhost','test','123456','test',3306);
        var_dump($dbh);
        //$user = mysqli_real_escape_string($dbh,$user);
        $sql = "select comments,last_visitor from guest_books where `user`= {$user} limit 1";
        var_dump($sql);
        $r = mysqli_query($dbh,$sql);
        var_dump(mysqli_error($dbh));
        var_dump($r);
        if($obj = mysqli_fetch_object($dbh,$r)){
            var_dump($obj);
            $this->comments = $obj->comments;
            $this->last_visitor = $obj->last_visitor;
        }
    }
}

$gb = new guest_book(10);
var_dump($gb);

